<html>
<head><meta charset="utf-8"><title>Why do we prevent defining statics via destructuring? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html">Why do we prevent defining statics via destructuring?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205285595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205285595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205285595">(Jul 28 2020 at 20:21)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">static</span><span class="w"> </span><span class="p">(</span><span class="n">FOO</span><span class="p">,</span><span class="w"> </span><span class="n">BAR</span><span class="p">)</span>: <span class="p">(</span><span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">);</span><span class="w"></span>
</code></pre></div>


<div class="codehilite"><pre><span></span><code>error: expected identifier, found `(`
 --&gt; src/lib.rs:1:8
  |
1 | static (FOO, BAR): (i32, i32) = (1, 2);
  |        ^ expected identifier
</code></pre></div>



<a name="205285913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205285913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205285913">(Jul 28 2020 at 20:23)</a>:</h4>
<p>Do patterns have name mangling?</p>



<a name="205285960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205285960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205285960">(Jul 28 2020 at 20:24)</a>:</h4>
<p><span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span> <code>static</code>s often feel a bit more "public" than let bindings, so I prioritize readability a bit more here. So I am slightly against doing so.</p>



<a name="205286049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286049">(Jul 28 2020 at 20:24)</a>:</h4>
<p>I mostly think that no one cared about this enough in the past to get this working, at least I personally did not see any discussions about this previously</p>



<a name="205286143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286143">(Jul 28 2020 at 20:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F/near/205285913">said</a>:</p>
<blockquote>
<p>Do patterns have name mangling?</p>
</blockquote>
<p>couldn't we just mangle <code>FOO</code> and <code>BAR</code> separately here?</p>



<a name="205286268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286268">(Jul 28 2020 at 20:26)</a>:</h4>
<p>If you were calling some <code>const fn</code> that returns a tuple in the initializer, how would you break it apart? I'd think that having two <code>static</code>s would be more readable than <code>FOO_BAR.0</code>.</p>



<a name="205286418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286418">(Jul 28 2020 at 20:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F/near/205286143">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F/near/205285913">said</a>:</p>
<blockquote>
<p>Do patterns have name mangling?</p>
</blockquote>
<p>couldn't we just mangle <code>FOO</code> and <code>BAR</code> separately here?</p>
</blockquote>
<p>Yes, but not for <code>static (): () = ();</code> and other patterns</p>



<a name="205286479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286479">(Jul 28 2020 at 20:27)</a>:</h4>
<p>Heh, I guess it would also be ambiguous with <code>static mut</code></p>



<a name="205286483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286483">(Jul 28 2020 at 20:27)</a>:</h4>
<p><code>static ()</code> doesn't have any identifiers we can reference though, so there isn't a point in storing them, is there</p>



<a name="205286585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286585">(Jul 28 2020 at 20:28)</a>:</h4>
<p>It should still create a symbol though, right?</p>



<a name="205286615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286615">(Jul 28 2020 at 20:28)</a>:</h4>
<p>What about adding <code>#[no_mangle]</code> and <code>pub</code> to that static, for example?</p>



<a name="205286641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286641">(Jul 28 2020 at 20:28)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="cp">#[link_name = </span><span class="s">&quot;Hey&quot;</span><span class="cp">]</span><span class="w"></span>
<span class="k">static</span><span class="w"> </span><span class="p">()</span>: <span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">();</span><span class="w"></span>
</code></pre></div>



<a name="205286656"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286656" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286656">(Jul 28 2020 at 20:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F/near/205286615">said</a>:</p>
<blockquote>
<p>What about adding <code>#[no_mangle]</code> and <code>pub</code> to that static, for example?</p>
</blockquote>
<p>what would <code>#[no_mangle]</code> even mean here</p>



<a name="205286672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286672">(Jul 28 2020 at 20:29)</a>:</h4>
<p>exactly</p>



<a name="205286749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286749">(Jul 28 2020 at 20:29)</a>:</h4>
<p>Also consider: or-patterns</p>



<a name="205286868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286868">(Jul 28 2020 at 20:30)</a>:</h4>
<p>or-patterns:</p>
<div class="codehilite"><pre><span></span><code><span class="k">static</span><span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">RESULT</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="nb">Err</span><span class="p">(</span><span class="n">RESULT</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">function</span><span class="p">(</span><span class="n">wow</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="205286874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286874">(Jul 28 2020 at 20:30)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="nb">None</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">huh</span><span class="p">)</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="kt">u8</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">None</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="205286937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286937">(Jul 28 2020 at 20:30)</a>:</h4>
<blockquote>
<p>variable <code>huh</code> is not bound in all patterns</p>
</blockquote>



<a name="205286945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286945">(Jul 28 2020 at 20:31)</a>:</h4>
<p>that's "easy", you have the same error as <code>let</code>:</p>
<div class="codehilite"><pre><span></span><code>variable `a` is not bound in all patterns
</code></pre></div>



<a name="205286960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205286960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205286960">(Jul 28 2020 at 20:31)</a>:</h4>
<p>oh, right</p>



<a name="205287096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287096">(Jul 28 2020 at 20:32)</a>:</h4>
<p>And I'd assume that it'd be <code>static (mut FOO, mut BAR) ...</code></p>



<a name="205287108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287108">(Jul 28 2020 at 20:32)</a>:</h4>
<p>I suppose you could just treat each ident binding as its own <code>static</code>, but it does make my brain hurt</p>



<a name="205287148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287148">(Jul 28 2020 at 20:32)</a>:</h4>
<p>Would that create 2 unsafe statics?</p>



<a name="205287189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287189">(Jul 28 2020 at 20:32)</a>:</h4>
<p>I'd be OK with the restriction, but I'm not sure how to work around it.</p>



<a name="205287220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287220">(Jul 28 2020 at 20:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="211727">Jonas Schievink</span> <a href="#narrow/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F/near/205287148">said</a>:</p>
<blockquote>
<p>Would that create 2 unsafe statics?</p>
</blockquote>
<p>IMO yes.</p>



<a name="205287362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287362">(Jul 28 2020 at 20:34)</a>:</h4>
<p><code>mut ident</code> patterns have become kinda rare</p>



<a name="205287372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287372">(Jul 28 2020 at 20:34)</a>:</h4>
<p>Like, if you have</p>
<div class="codehilite"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">thing</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="p">(</span><span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>how could you get each <code>i32</code> into a static without calling the function twice?</p>



<a name="205287388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287388">(Jul 28 2020 at 20:34)</a>:</h4>
<p>Now, maybe <em>because</em> it's <code>const</code>, calling it twice isn't a problem at all...</p>



<a name="205287879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205287879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Goat <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205287879">(Jul 28 2020 at 20:38)</a>:</h4>
<p>A <code>const fn</code> can't really be an expensive computation today, but once/if we get <code>if</code>s and loops in <code>const fn</code>, that might become a compile-time concern in certain very specific cases</p>



<a name="205288049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205288049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Goat <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205288049">(Jul 28 2020 at 20:39)</a>:</h4>
<p>if every single function which doesn't do FFI/system calls/memory allocations becomes a <code>const fn</code> at some point, some of them would certainly visibly affect compile time</p>



<a name="205288139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205288139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Goat <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205288139">(Jul 28 2020 at 20:40)</a>:</h4>
<p>that's a rather niche thing to optimize for, though</p>



<a name="205288143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205288143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205288143">(Jul 28 2020 at 20:40)</a>:</h4>
<p>In these cases it can be solved by using</p>
<div class="codehilite"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">WOW</span>: <span class="p">(</span><span class="kt">i32</span><span class="p">,</span><span class="w"> </span><span class="kt">i32</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">thing</span><span class="p">();</span><span class="w"></span>
<span class="k">const</span><span class="w"> </span><span class="n">LEFT</span>: <span class="kt">i32</span> <span class="o">=</span><span class="w"> </span><span class="n">WOW</span><span class="p">.</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="k">const</span><span class="w"> </span><span class="n">RIGHT</span>: <span class="kt">i32</span> <span class="o">=</span><span class="w"> </span><span class="n">WOW</span><span class="p">.</span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="205288167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205288167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205288167">(Jul 28 2020 at 20:40)</a>:</h4>
<p>The value of <code>WOW</code> is cached, so thing should only get evaluated once</p>



<a name="205288208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205288208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205288208">(Jul 28 2020 at 20:41)</a>:</h4>
<p>aren't nullary <code>const fn</code> also cached?</p>



<a name="205288241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205288241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205288241">(Jul 28 2020 at 20:41)</a>:</h4>
<p>maybe <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="205288569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205288569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Goat <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205288569">(Jul 28 2020 at 20:44)</a>:</h4>
<p>This works, but the syntax is somewhat bulky; after all, tuple patterns are just syntactic sugar for:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">_temporary_tuple</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">create_tuple</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">_temporary_tuple</span><span class="p">.</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">_temporary_tuple</span><span class="p">.</span><span class="mi">1</span><span class="p">;</span><span class="w"></span>

<span class="c1">// equivalent to:</span>
<span class="kd">let</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">create_tuple</span><span class="p">();</span><span class="w"></span>
</code></pre></div>



<a name="205288819"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205288819" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Goat <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205288819">(Jul 28 2020 at 20:46)</a>:</h4>
<p>My point here is that if we have a way of destructuring output of a <code>const fn</code> into two constants, there's no reason not to add convenience syntax for that and that we <em>should</em> add it eventually</p>



<a name="205289097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Why%20do%20we%20prevent%20defining%20statics%20via%20destructuring%3F/near/205289097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Why.20do.20we.20prevent.20defining.20statics.20via.20destructuring.3F.html#205289097">(Jul 28 2020 at 20:49)</a>:</h4>
<p>yeah, I don't think my solution is optimal here.</p>
<p>I do however think that patterns in consts/statics require some implementation and design effort and are fairly far below an <code>awesome/effort</code> ratio of 1</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>